package com.wn.controller;

import com.common.entity.Hotel;
import com.common.entity.PageParam;
import com.common.entity.Rsp;
import com.wn.service.HotelServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class HotelController {

    @Autowired
    HotelServiceImpl hotelService;


//    @SystemControllerLog(description = "分页查询用户信息")
    @PostMapping("/searchSomeNewsHotelByPage")
//    @RequireRoles(roles = {"admin","super_admin","reception","guide","tourist"},index = 1)
    @ApiOperation("查询所有 支持 多条件 分页 排序 查询")
    public Rsp searchSomeByPage(@RequestBody PageParam<Hotel> hotelPageParam, @RequestHeader("token") String token) {
        System.out.println(hotelPageParam);
        return Rsp.success(hotelService.searchSomeByPage(hotelPageParam));
    }

    @PostMapping("/addOne")
    @ApiOperation("添加")
    public Rsp addOne(@RequestBody Hotel hotel,@RequestHeader("token") String token){
        System.out.println(hotel.getHotelPhoto());
        return hotelService.addOne(hotel);
    }

    @PostMapping("/update")
    @ApiOperation("修改")
    public Rsp update(@RequestBody Hotel hotel,@RequestHeader("token") String token){
        System.out.println(hotel.toString());
        return hotelService.update(hotel);
    }

    @PostMapping("/deleteLogical")
    @ApiOperation("逻辑删除")
    public Rsp deleteLogical(@RequestBody Hotel hotel){
        return hotelService.deleteLogical(hotel);
    }

    @PostMapping("/findHotelAndHotelroomitem")
    @ApiOperation("根据酒店id查询对应房间信息")
    public List<Hotel> findHotelAndHotelroomitem(@RequestBody String id,@RequestHeader("token") String token){
        List<Hotel> hotelAndHotelroomitem = hotelService.getHotelAndHotelroomitem(id);
        return hotelAndHotelroomitem;
    }

    @GetMapping("getById")
    @ApiOperation("根据userId查询相关酒店")
    public List<Hotel> getById(Hotel hotel,@RequestHeader("token") String token){
        List<Hotel> byId = hotelService.getById(hotel.getId());
        return byId;
    }

    @PostMapping("/updateGrade")
    @ApiOperation("修改酒店热度")
    public Rsp updateGrade(@RequestBody Hotel hotel,@RequestHeader("token") String token){
       return hotelService.updatehert(hotel.getId(),hotel.getGrade());
    }
}
